package com.lyf.core.ui.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewbinding.ViewBinding;

import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.core.AttachPopupView;
import com.lyf.core.BuildConfig;

public abstract class BaseAttachPopup<VB extends ViewBinding> extends AttachPopupView {

    protected VB mViewBinding;

    public BaseAttachPopup(@NonNull Context context) {
        super(context);
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        mViewBinding = getViewBinding();
    }

    public abstract VB getViewBinding();

    @Override
    public void destroy() {
        super.destroy();
        mViewBinding = null;
    }

    public void showMessage(String message) {
        ToastUtils.showShort(message);
    }

    public void showMessage(int message) {
        ToastUtils.showShort(message);
    }

    public View getContentView() {
        if (attachPopupContainer.getChildAt(0) == null) {
            dismiss();
            if (BuildConfig.DEBUG) {
                throw new RuntimeException(" RuntimeException :BaseAttachPopup attachPopupContainer.getChildAt(0) is null....");
            }
        }
        return attachPopupContainer.getChildAt(0);
    }

}
